// run: $exec < input
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

int const maxn = 200;
unsigned int a, b, c, d, l, r;
int n;
unsigned int al[maxn], ar[maxn];

bool inrange(int x, int l, int r)
{
	return l <= x && x <= r;
}

bool overlap(int i, int j)
{
	if (al[i] <= al[j] && ar[j] <= ar[i]) return true;
	if (al[j] <= al[i] && ar[i] <= ar[j]) return true;
	return inrange(al[i], al[j], ar[j]) || inrange(ar[i], al[j], ar[j]);
}

bool judge()
{
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			for (int k = j + 1; k <= n; k++) {
				if (!overlap(i, j) && !overlap(i, k) && !overlap(j, k))
					return true;
			}
	return false;
}

int main()
{
	std::ios::sync_with_stdio(false);
	int T; std::cin >> T;
	while (T--) {
		std::cin >> n >> l >> r >> a >> b >> c >> d;
		if (n <= 0) {
			al[1] = l; ar[1] = r;
			for (int i = 2; i <= n; i++) {
				al[i] = al[i - 1] * a + b;
				ar[i] = ar[i - 1] * c + d;
			}
			for (int i = 1; i <= n; i++)
				if (al[i] > ar[i]) std::swap(al[i], ar[i]);
			if (judge()) std::cout << "YES\n";
			else std::cout << "NO\n";
			continue;
		}
		long long min = std::max(l, r), max = std::min(l, r);
		auto tl = l;
		auto tr = r;
		auto pl = l;
		auto pr = r;
		for (int i = 2; i <= n; i++) {
			l = pl * a + b; r = pr * c + d;
			pl = l; pr = r;
			if (l > r) std::swap(l, r);
			min = std::min(min, (long long)r);
			max = std::max(max, (long long)l);
		}
	//	std::cerr << ":: " << min << " " << max << "\n";
		pl = tl; pr = tr;
		bool ok = false;
		if (std::min(tl, tr) > min && std::max(tl, tr) < max) ok = true;
		for (int i = 2; i <= n; i++) {
			l = pl * a + b; r = pr * c + d;
			pl = l; pr = r;
			if (l > r) std::swap(l, r);
			if (l > min && r < max) {
				ok = true;
				break;
			}
		}
		if (ok) std::cout << "YES\n";
		else std::cout << "NO\n";
	}
}

